<script setup>
  import { getArticleChannelService } from '@/api/article.js'
  import { ref } from 'vue'

  defineProps({
    modelValue: {
      type: [Number, String]
    }
  })

  const emit = defineEmits(['update:modelValue'])

  const channelList = ref([])
  const getChannelList = async () => {
    const res = await getArticleChannelService()
    channelList.value = res.data.data
  }
  getChannelList()
</script>

<template>
  <!--
    Vue的v-model本质是语法糖，会被编译为：
    绑定modelValue属性
    监听update:modelValue事件
  -->
  <el-select
    placeholder="请选择"
    :modelValue="modelValue"
    @update:modelValue="emit('update:modelValue', $event)"
  >
    <el-option
      v-for="channel in channelList"
      :label="channel.cate_name"
      :value="channel.id"
      :key="channel.id"
    ></el-option>
  </el-select>
</template>
<style lang="scss" scoped>
  .el-select {
    width: 240px;
  }
</style>
